package com.atguigu.eduService.controller.front;

import com.atguigu.common.Result;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.entity.EduTeacher;
import com.atguigu.eduService.service.EduCourseService;
import com.atguigu.eduService.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Summerday
 */

@RestController
@RequestMapping("/eduService/teacherFront")
//@CrossOrigin
public class TeacherFrontController {


    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    /**
     * 分页查询讲师
     */
    @ApiOperation(value = "分页查询信息")
    @GetMapping("/getPage")
    public Result getPage(
            @ApiParam(name = "current", value = "当前页码数", required = true)
            @RequestParam("current") Integer current,
            @ApiParam(name = "size", value = "每页记录数", required = true)
            @RequestParam("size") Integer size) {

        Page<EduTeacher> page = new Page<>(current, size);

        Map<String,Object> map = teacherService.getTeacherFrontList(page);
        return Result.ok().data(map);

    }
    @ApiOperation(value = "查询讲师信息及课程信息")
    @GetMapping("getTeacherInfo/{id}")
    public Result getTeacherInfo(@PathVariable("id")String id){

        EduTeacher teacher = teacherService.getById(id);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courses = courseService.list(wrapper);
        return Result.ok().data("teacher",teacher).data("courses",courses);
    }

}
